package com.ifonly.ar.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;

/**
 * @author ifonly
 * @version 1.0 2015-12-03 15:50
 * @since JDK 1.6
 */
public class ProxyFactory {

    @SuppressWarnings("unchecked")
    public static <T> T newProxyInstance(Object target, InvocationHandler handler) {
        Class<T> clazz = (Class<T>) target.getClass();
        return newProxyInstance(clazz, handler);
    }

    @SuppressWarnings("unchecked")
    public static <T> T newProxyInstance(Class<T> clazz, InvocationHandler handler) {
        Object o = Proxy.newProxyInstance(clazz.getClassLoader(), clazz.getInterfaces(), handler);
        return (T) o;
    }

}
